$(function () {
    $("#sub").click(function () {
        clearAlert();
        checkAccount();
        checkPassword();
        checkRPassword();
        checkTelphone();
        checkEmail();
        if (checkAccount() & checkPassword() & checkRPassword() & checkTelphone() & checkEmail()) {
            $.ajax({
                url: "/UserController/UserTwo",
                type: "Post",
                contentType: "application/json",
                data: JSON.stringify(
                    {
                        "account": $("#account").val(),
                        "password": $("#password").val(),
                        "tel": $("#telphone").val(),
                        "email": $("#email").val()
                    }
                ),
                success: function (data) {
                    switch (data) {
                        case true:
                            location.href = "/index.jsp";
                            break;
                        case false:
                            $("#apWrongInfo").css("display", "block");
                            break;
                    }
                }
            });
        }
    });
});

// aUsedInfo
function checkAccount() {
    if ($("#account").val() == "") {
        $("#aNullInfo").css("display", "block");
        return false;
    }
    return true;
}

function checkPassword() {
    if ($("#password").val() == "") {
        $("#pNullInfo").css("display", "block");
        return false;
    }
    ;
    return true;
}

function checkRPassword() {
    if ($("#rPassword").val() == "") {
        $("#rNullInfo").css("display", "block");
        return false;
    }
    ;
    return true;
}

function checkTelphone() {
    if ($("#telphone").val() == "") {
        $("#tNullInfo").css("display", "block");
        return false;
    }
    ;
    return true;
}

function checkEmail() {
    if ($("#email").val() == "") {
        $("#eNullInfo").css("display", "block");
        return false;
    }
    ;
    return true;
}

function clearAlert() {
    $(".alert").css("display", "none");
}